home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / inpfiel.exe / INPFIELD.H < prev   
C/C++ Source or Header  |  1993-01-23  |  4KB  |  115 lines

  1. // inpfield.h - generic input field class
  2. //
  3. // This header declares a set of classes for creating generic input
  4. // fields in dialog boxes.  The InpField class is derived from TGroup,
  5. // and contains a TInputLine member (inpLine).  The InpField
  6. // constructor is passed a pointer to an abstract InpData class.
  7. // The InpData class is used to store values that are input via the
  8. // TInputLine.  InpData provides methods for validation, assignment,
  9. // string conversion, and error message text generation.  Derive
  10. // your own InpData class with these methods overriden, and pass a pointer
  11. // to an instance of your class to InpField.  A usable InpData subclass
  12. // is provided in this module for integer input (IntInpData).  Here's
  13. // how you would use it within a dialog box's constructor:
  14. //
  15. //    const initVal=1, minVal=1, maxVal=100;
  16. //    IntInpData *myInt = new IntInpData(initVal, minVal, maxVal);
  17. //
  18. //    const orgX=1, orgY=4, dataLen=2;
  19. //    const char *myLabel="Input data here:";
  20. //    InpField *myIntField = new InpField(
  21. //       orgX, orgY, myInt, dataLen, myLabel
  22. //    );
  23. //    insert(myIntField);
  24. //
  25. // This would place a label "Input data here:" at (1,4) in the dialog box,
  26. // with an adjacent TInputLine that accomodates a data width of 2.
  27. // The TInputLine would initialy display "1" (initVal).
  28. // Any value entered into this field (via TAB or CR) is validated before it
  29. // is assigned to the IntInpData (myInt).  If entered values are
  30. // outside 1-100, a message box appears to warn the user, and the
  31. // input field remains focused.
  32. //
  33. // If the focus is lost before TAB or CR are pressed (eg. mouse click),
  34. // then the InputLine is restored to the internally stored value (myInt).
  35. // This means that TAB or CR must be used to actually change the value.
  36. //
  37. //
  38. // Christensen OnLine, 1993
  39. //
  40. //$Log: inpfield.h $
  41. //Revision 1.4  1993/01/23  15:40:43  matt
  42. //Fixed/re-sent to CIS
  43. //
  44. //Revision 1.3  1993/01/23  14:38:18  matt
  45. //Uploaded to CIS
  46. //
  47. //Revision 1.2  1993/01/23  10:07:47  matt
  48. //Experiments with selectAll
  49. //
  50. //Revision 1.1  1993/01/13  20:57:22  matt
  51. //Input field with validation
  52. //
  53. #define Uses_TEvent
  54. #define Uses_TPoint
  55. #define Uses_TRect
  56. #define Uses_TInputLine
  57. #define Uses_TLabel
  58. #define Uses_MsgBox
  59. #define Uses_TGroup
  60. #include <tv.h>
  61.  
  62. // Input field palette - transparent to TDialog for TInputLine and TLabel
  63. //
  64. #define cpInpField "\x01\x02\x03\x04\x05\x06\x07\x08"\
  65.                    "\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"\
  66.                    "\x11\x12\x13\x14\x15"
  67.  
  68. const short InpDataMAXLEN = 80;
  69.  
  70. ///////////////////////////////////////////////////////////////////////
  71. class InpData : public TObject
  72. ///////////////////////////////////////////////////////////////////////
  73. {
  74. public:
  75.    virtual int isValid(char *)=0;           // Is passed string valid?
  76.    virtual InpData& operator = (char *)=0;  // Assign internal value
  77.    virtual char * getText(short len)=0;     // Convert internal value
  78.    virtual const char * errMsg()=0;         // Err msg str for invalid val
  79.  
  80. protected:
  81.    static char convBuf[InpDataMAXLEN+1];
  82. };
  83.  
  84. ///////////////////////////////////////////////////////////////////////
  85. class IntInpData : public InpData
  86. ///////////////////////////////////////////////////////////////////////
  87. {
  88. public:
  89.    IntInpData(int initValue, int aMin, int aMax);
  90.    virtual int isValid(char *);
  91.    virtual InpData& operator = (char *);
  92.    virtual char * getText(short len);
  93.    virtual const char * errMsg();
  94.  
  95.    int value,min,max;
  96. };
  97.  
  98. ///////////////////////////////////////////////////////////////////////
  99. class InpField : public TGroup
  100. ///////////////////////////////////////////////////////////////////////
  101. {
  102. public:
  103.    InpField(int orgX, int orgY, InpData *theInpData,
  104.       short aDataLen, const char *aLabel="");
  105.    void handleEvent(TEvent& event);
  106.    TPalette& getPalette() const;
  107.    int getSizeX() {return size.x;}
  108.  
  109. protected:
  110.    InpData *inpData;
  111.    short dataLen;
  112.    Boolean dataSynced;
  113.    TInputLine *inpLine;
  114. };
  115.